# Python 2.6.4
# Project Euler, Problem 174
# Copyright 2010 Talha Zaman

from mine import timed

def cumsum(lim, init):
    cum = [0]
    n = init
    while n <= lim:
        cum.append(n + cum[-1])
        n += 8
    return cum

@timed
def laminae(tiles):
    count = 0
    L = {}
    for init in [8, 12]:
        add, sub = 0, 0
        cum = cumsum(tiles, init)
        while add < len(cum):
            while cum[add] - cum[sub] > tiles:
                sub += 1
            count += add - sub
            for i in range(sub, add+1):
                try:
                    L[cum[add] - cum[i]] += 1
                except KeyError:
                    L[cum[add] - cum[i]] = 1
            add += 1
    return sum(1 for x in L.values() if x in range(1,11))

print laminae(1000000)
